package mybatis.main;

import java.io.Reader;
import java.util.List;

import mybatis.domain.User;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import static java.lang.System.out;

//mapper01.xml, SqlMapConfig.xml
public class Main01 {	
	public static void main(String[] args) throws Exception{		
		Reader reader = Resources.getResourceAsReader("config/SqlMapConfig.xml");		
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);		
		SqlSession sqlSession = sqlSessionFactory.openSession();
		
		List<User> list = sqlSession.selectList("user.getUsers");
		out.println("[getUsers]");
		for(User user: list) out.println(user);

		out.println("[getUser]");
		User member = sqlSession.selectOne("user.getUser", "u01");
		out.println(member);
	}
}